home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / DCLAP 6d / dclap6d / DBio / DSeqAsmView.cpp < prev    next >
Text File  |  1996-07-05  |  21KB  |  964 lines

  1. // DSeqAsmView.cpp
  2.  
  3.  
  4. #define TESTVARHEIGHT
  5. #define TESTZOOM
  6. #undef  USEDRAWBASE
  7. #define POPBASECALL
  8.  
  9.  
  10. #include "DSeqViews.h"
  11. #include "DSeqAsmView.h"
  12. #include "DAsmSequence.h"
  13.  
  14. #include <ncbi.h>
  15. #include <dgg.h>
  16. #include <Dvibrant.h>
  17. #include <DApplication.h>
  18. #include <DClipboard.h>
  19. #include <DControl.h>
  20. #include <DWindow.h>
  21. #include <DRichViewNu.h>
  22. #include <DTableView.h>
  23. #include <DViewCentral.h>
  24. #include <DTask.h>
  25. #include <DTracker.h>
  26. #include <DMenu.h>
  27. #include <DUtil.h>
  28. #include <DFindDlog.h>
  29. #include "DSeqFile.h"
  30. #include "DSeqEd.h"
  31. #include "DSeqMail.h"
  32. #include "DSeqCmds.h"
  33. #include "DSeqChildApp.h"
  34. #include "DSeqPrint.h"
  35. #include "DSeqPict.h"
  36. #include "DSeqDoc.h"
  37.  
  38.  
  39.  
  40.  
  41. enum {
  42.     kORFxtraHeight = 4,
  43.     kTracextraHeight = 64,
  44.     kTracePointWidth = 3,  // ?? 1, 2 or 3 ? 
  45.     knadaxxx
  46.     };
  47.     
  48. typedef unsigned long  colorVal;
  49.  
  50. Local short gAlnCharWidth  = 12;
  51. Local short gAlnCharHeight = 15;
  52. Local short gBaseCharWidth = 12;
  53. Local short gRealCharWidth = 12;
  54. Local Boolean gSwapBackground = false;
  55.  
  56. extern "C" void Nlm_SelectBackColor(Nlm_Uint1 red, Nlm_Uint1 green, Nlm_Uint1 blue);
  57. extern "C" void Nlm_SetBackColor (Nlm_Uint4 color);
  58. extern "C" Nlm_Boolean Nlm_MacPopListClick(Nlm_GraphiC m, Nlm_PoinT pt);
  59. extern "C" Nlm_Boolean Nlm_DoClick (Nlm_GraphiC a, Nlm_PoinT pt);
  60. extern "C" Nlm_GraphiC Nlm_GetParent (Nlm_GraphiC a);
  61.  
  62. //inline 
  63. static short BaseCharWidth()
  64. {
  65. #ifdef TESTZOOM
  66.     if (gBaseCharWidth>5) gBaseCharWidth= Nlm_CharWidth('G');
  67.     gRealCharWidth= Nlm_CharWidth('G');
  68. #else
  69.     gBaseCharWidth= gRealCharWidth= Nlm_CharWidth('G');
  70. #endif
  71.     return gBaseCharWidth;
  72. }
  73.  
  74.  
  75. #ifdef POPBASECALL
  76.  
  77. #include "DBaseCallPop.h"
  78.  
  79.  
  80. //DBaseCallPop* gBaseCallPop = NULL;
  81.  
  82.  
  83. DBaseCallPop::DBaseCallPop(long id, DAsmView* itsSuperior):
  84.         DPopupList(id, itsSuperior->fDoc), 
  85.         fAsmView(itsSuperior), 
  86.         fVisible(false), fRow(0), fCol(0) 
  87. {
  88.     Nlm_LoadRect( &fPoprect, 0,0,0,0);
  89.     AddItem("no change"); // default
  90.     AddItem("clear");
  91.     AddItem("set A");
  92.     AddItem("set C");
  93.     AddItem("set G");
  94.     AddItem("set T");
  95.     // ?? stats display at position, other functions at trace position?
  96. }
  97.  
  98.  
  99.  
  100. void DBaseCallPop::LimitTrace(short item)
  101. {
  102. #if 0
  103.             // this isn't working
  104.         // disable choices when trace view is limited to one base !/
  105.     short i;
  106.     item += 3; // convert from base 0..3 to popup item 3..6
  107.     
  108.     if (item<3 || item>6)
  109.         for ( i=3; i<7; i++) SetItemStatus(i,true);
  110.     else {
  111.         for ( i=3; i<7; i++) SetItemStatus(i,false);
  112.         SetItemStatus(item,false);
  113.         }
  114. #endif        
  115. }
  116.  
  117. void DBaseCallPop::Hold(Nlm_PoinT mouse)
  118. {
  119.   Nlm_GraphiC m = Nlm_GetParent ((Nlm_GraphiC)fPopup);
  120. #ifdef WIN_MAC
  121.     if ( Nlm_DoClick( (Nlm_GraphiC) m, mouse) ) ;
  122.         // !! WORKS, gets us to DSeqAsmDoc::IsMyAction(kBaseCallPop) 
  123. #endif
  124.  
  125. }
  126.          
  127.  
  128. void DBaseCallPop::Release(Nlm_PoinT mouse)
  129. {
  130.     //Message(MSG_OK,"DBaseCallPop::Release"); // this is seen
  131. }
  132.  
  133.  
  134. Boolean DBaseCallPop::IsMyAction(DTaskMaster* action) 
  135. {
  136.     switch(action->Id()) {
  137.             
  138.      case kBaseCallPopup: {
  139.                  // call here from DSeqAsmDoc::IsMyAction()
  140.         DAsmSequence* aSeq = NULL;
  141.         TraceBase tr, * tra = NULL;
  142.         Boolean doupdate= false;
  143.         short    mode= this->GetValue();
  144.         long    i, maxcol= 0, atcol = fCol;
  145.         
  146.         if (mode>1) {  
  147.             aSeq= (DAsmSequence*)fAsmView->fSeqList->SeqAt(fRow);
  148.             maxcol= aSeq->NumPoints();
  149.             if (mode>2) // make sure we don't overwrite other base!
  150.                 for (i=0; 
  151.                     aSeq->TraceAt(atcol).base>' ' && atcol<maxcol && i<20; 
  152.                     i++, atcol++) ;
  153.             tr = aSeq->TraceAt(atcol);
  154.             }
  155.             
  156.         switch (mode) {
  157.             case 1:  break;  // nothing...
  158.             case 2:  tr.base= 0; doupdate= true; break;     
  159.             case 3:  tr.base= 'A'; doupdate= true; break;  
  160.             case 4:  tr.base= 'C'; doupdate= true; break;     
  161.             case 5:     tr.base= 'G'; doupdate= true; break; 
  162.             case 6:  tr.base= 'T'; doupdate= true; break;
  163.             }
  164.             
  165.         if (doupdate) {
  166.             Nlm_RecT  r;
  167.             aSeq->SetTraceAt(atcol, tr);
  168.             aSeq->SetChanged(true);
  169.             // !! need to update aSeq->fBases sometime w/ new set !!
  170.             // need undo/redo of change !
  171.             
  172.             fAsmView->GetCellRect(fRow, fCol, r);  
  173.             r.left  = Min( r.left, fPoprect.left-20);
  174.             r.right = Max( r.right, fPoprect.right+20);
  175.             fAsmView->InvalRect( r);  // fPoprect
  176.  
  177.             if (fAsmView->fDoc->fAlnIndex) {
  178.                 fAsmView->fDoc->fAlnIndex->GetRowRect( fRow, r);
  179.                 fAsmView->fDoc->fAlnIndex->InvalRect( r);
  180.                 }
  181.             }
  182.       return true;
  183.         }
  184.         
  185.         default:
  186.             return DPopupList::IsMyAction(action);
  187.         }
  188. }
  189.  
  190.  
  191.  
  192. void DBaseCallPop::Show(Nlm_PoinT mouse)
  193. {
  194.     long row, col;
  195.  
  196.     fAsmView->PointToCell( mouse, row, col);
  197.     if (col) col--; // fix off-by-one error
  198.     if ( row >=0 && row < fAsmView->GetMaxRows()
  199.      && col >= 0 && col < fAsmView->GetMaxCols()) {
  200.         Nlm_RecT  r;
  201.         short   w, h;
  202.         fMouse= mouse;
  203.         fRow= row;
  204.         fCol= col;
  205.  
  206.         this->GetPosition(r);
  207.         w= r.right - r.left;
  208.         h= r.bottom- r.top;
  209.         r.left= mouse.x - 10;  // make sure mouse is in rect..
  210.         r.top = mouse.y - 10;
  211.         r.right= r.left + w;
  212.         r.bottom= r.top + h;
  213.         fPoprect= r;
  214.         this->SetPosition(r);        
  215.         
  216.         Show();
  217.         }
  218. }
  219.  
  220. void DBaseCallPop::Show()
  221. {
  222.     if (!fVisible) {
  223.         fVisible= true;
  224.         DPopupList::Show(); 
  225.         this->SetValue(1); // ?? force label to show?
  226.         Enable();
  227.         }
  228. }
  229.  
  230. void DBaseCallPop::Hide()
  231. {
  232.     if (fVisible) {
  233.         fVisible= false;
  234.         Disable();
  235.         DPopupList::Hide();
  236.         fAsmView->InvalRect(fPoprect);
  237.         }
  238. }
  239.  
  240. #endif
  241.  
  242.  
  243.  
  244.  
  245.  
  246. //class DAsmView : public DAlnView  
  247.  
  248.  
  249. DAsmView::DAsmView( long id, DView* itsSuper, DSeqDoc* itsDocument, DSeqList* itsSeqList, 
  250.                                 long pixwidth, long pixheight) :
  251.     DAlnView( id, itsSuper, itsDocument, itsSeqList,  pixwidth,  pixheight),
  252.     fHaveAutoseq(false), fBaseOnTrace(true)                  
  253.     fKind= kindAlnView;
  254.     for (short t=0; t<4; t++) fShowTrace[t]= true;
  255.     
  256. #ifdef TESTZOOM
  257.     //DSequence* aSeq= fSeqList->SeqAt(0);
  258.     if (1) { // (aSeq && aSeq->ShowTrace())
  259.         fHaveAutoseq= true;
  260.         gBaseCharWidth= kTracePointWidth; 
  261.         }
  262.     else gBaseCharWidth= Nlm_stdCharWidth;
  263. #endif
  264.  
  265.     gAlnCharWidth= gBaseCharWidth; //Nlm_stdCharWidth; //BaseCharWidth();   
  266.     gAlnCharHeight= Nlm_stdLineHeight;
  267.     
  268. #ifdef POPBASECALL
  269.   Nlm_PoinT  nps, saveps;
  270. #if 1
  271.     fDoc->GetNextPosition( &saveps);
  272.     nps.x= 1; nps.y= 1; // locate dialog item 
  273.     fDoc->SetNextPosition( nps);
  274. #endif
  275.     
  276.     DBaseCallPop* bcpop= new DBaseCallPop( kBaseCallPopup, this);  
  277.     fBaseCallPop= bcpop;  
  278.     bcpop->fVisible= true;
  279.     bcpop->Hide();  
  280. #if 1
  281.     fDoc->SetNextPosition( saveps);
  282. #endif
  283. #endif
  284.  
  285. }
  286.  
  287.  
  288. DAsmView::~DAsmView()
  289. {
  290. }
  291.  
  292.                 
  293.  
  294. void DAsmView::CheckViewCharWidth()
  295. {
  296.     if (fEditSeq) {
  297.         Nlm_RecT vr;
  298.         ViewRect( vr);
  299.         long cwidth= (vr.right - vr.left) / GetItemWidth(0);
  300.         fEditSeq->SetColumns( cwidth);
  301.         }
  302. }
  303.  
  304.  
  305. void DAsmView::GetReadyToShow()
  306. {
  307.     // assume port is set??
  308.     SelectFont();  
  309.     gAlnCharWidth = BaseCharWidth();   
  310.         // use Nlm_FontHeight for background color to adjoin among rows
  311.     gAlnCharHeight= Nlm_FontHeight(); //Nlm_LineHeight(); // + 2; 
  312.     
  313.     //SetItemWidth(0, GetMaxCols(), gAlnCharWidth); // done in UpdateAllWidths
  314.     this->UpdateAllWidths(); 
  315.     this->UpdateSize();  // need before GetMaxRows()!
  316.  
  317. #ifdef TESTVARHEIGHT
  318.     long i, nrow= GetMaxRows();
  319.     for (i= 0; i<nrow; i++) {
  320.         short ht= gAlnCharHeight;
  321.         DSequence* aSeq= fSeqList->SeqAt(i);
  322.         if (aSeq && aSeq->ShowORF()) ht += kORFxtraHeight;
  323.         if (aSeq && aSeq->ShowTrace()) ht += kTracextraHeight;
  324.         SetItemHeight(i, 1, ht);
  325.         }    
  326. #else
  327.     SetItemHeight(0, GetMaxRows(), gAlnCharHeight);
  328. #endif
  329. }
  330.  
  331.  
  332.  
  333.  
  334.  
  335. void DAsmView::Drag(Nlm_PoinT mouse)
  336. {
  337.     DAlnView::Drag(mouse); // sets fMouseStillDown= true
  338. }
  339.  
  340. void DAsmView::Hold(Nlm_PoinT mouse)
  341. {
  342. #ifdef POPBASECALL
  343.     if (fBaseCallPop) {
  344.         if (!fBaseCallPop->fVisible) fBaseCallPop->Show(mouse);
  345.         if ( fBaseCallPop->fVisible) fBaseCallPop->Hold(mouse);
  346.         }
  347. #endif
  348.     DAlnView::Hold(mouse);
  349. }
  350.  
  351. void DAsmView::Release(Nlm_PoinT mouse)
  352. {
  353. #ifdef POPBASECALL
  354.     if (fBaseCallPop) {
  355.       if ( fBaseCallPop->fVisible) fBaseCallPop->Hide();
  356.         if (!fBaseCallPop->fVisible) fBaseCallPop->Release(mouse);
  357.         }
  358. #endif
  359.     DAlnView::Release(mouse);
  360. }
  361.  
  362. void DAsmView::DoubleClickAt(long row, long col)
  363. {
  364. }
  365.  
  366. void DAsmView::Click(Nlm_PoinT mouse)
  367. #if 0
  368.     DAlnView::Click( mouse);
  369. #else
  370.     long     row, col;
  371.     Nlm_CaptureSlateFocus((Nlm_SlatE) fPanel); // for CharHandler !
  372.     PointToCell( mouse, row, col);
  373.     SeqMeter(row,col);
  374.     if (fMaskLevel<1 && IsSelected(row, col)) {
  375.  
  376.         }
  377.     else {
  378.         fTabSelector= new DTabSelector( this);
  379.         fCurrentTracker= fTabSelector;
  380.         }
  381.     DTableView::Click( mouse);
  382. #endif
  383. }
  384.  
  385.  
  386. void DAsmView::TrackMouse( short aTrackPhase,
  387.                     Nlm_PoinT& anchorPoint, Nlm_PoinT& previousPoint,
  388.                     Nlm_PoinT& nextPoint,    Nlm_Boolean mouseDidMove)
  389. {
  390.     DAlnView::TrackMouse( aTrackPhase, anchorPoint, previousPoint, nextPoint,mouseDidMove); 
  391. }
  392.  
  393.  
  394. void DAsmView::TrackFeedback( short aTrackPhase,
  395.                     const Nlm_PoinT& anchorPoint, const Nlm_PoinT& previousPoint,
  396.                     const Nlm_PoinT& nextPoint, Nlm_Boolean mouseDidMove, Nlm_Boolean turnItOn)
  397. {
  398. #if 1
  399.     DAlnView::TrackFeedback( aTrackPhase, anchorPoint, previousPoint, nextPoint,
  400.                     mouseDidMove, turnItOn);
  401. #else
  402.     long     row, col;
  403.     if (mouseDidMove && aTrackPhase == DTracker::trackContinue ) { // 2 == trackContinue
  404.         PointToCell( nextPoint, row, col);
  405.         SeqMeter(row,col);
  406.         }
  407.     DTableView::TrackFeedback( aTrackPhase, anchorPoint, previousPoint, nextPoint,
  408.                     mouseDidMove, turnItOn);
  409. #endif
  410. }
  411.  
  412.  
  413. void DAsmView::SingleClickAt(long row, long col)
  414. {
  415. #if 1
  416.          DAlnView::SingleClickAt(row,  col);
  417. #else
  418.     if (!(fLocked || gKeys->shift() || gKeys->command() || gKeys->option() )) {  
  419.         SetEmptySelection( true); 
  420.         if (fDoc->fAlnIndex) fDoc->fAlnIndex->SetEmptySelection( true); 
  421.         InstallEditSeq(row,col,col,false);
  422.         }
  423.     else     if (fMaskLevel>0) {
  424.         Nlm_RecT r;
  425.         DSequence* ag= fSeqList->SeqAt(row); 
  426.         if (ag) {
  427.             if (gKeys->shift()) ag->SetMaskAt(col,fMaskLevel);
  428.             else ag->FlipMaskAt(col,fMaskLevel);
  429.             }
  430.         GetCellRect( row, col, r);
  431.         InvalRect( r);
  432.         }
  433.     else
  434.          DTableView::SingleClickAt(row,  col);
  435. #endif
  436. }
  437.  
  438.     
  439.  
  440.  
  441. void DAsmView::Scroll(Boolean vertical, DView* scrollee, long newval, long oldval)
  442. {
  443.     DAlnView::Scroll(vertical, scrollee, newval, oldval);
  444. }
  445.  
  446.  
  447.  
  448.  
  449.  
  450. void DAsmView::UpdateWidth(DSequence* aSeq)
  451. {     
  452.     long alnlen;
  453.     if (fHaveAutoseq)  
  454.         alnlen= ((DAsmSequence*)aSeq)->NumPoints() + 30;
  455.     else
  456.         alnlen= aSeq->LengthF() + 30;
  457.     if (alnlen > GetMaxCols()) ChangeColSize( -1, alnlen-GetMaxCols());  
  458.     SetItemWidth( 0, GetMaxCols(), gAlnCharWidth); 
  459.     if (fMaskLevel>0 || aSeq->Masks()) aSeq->FixMasks();
  460. }
  461.  
  462. void DAsmView::UpdateAllWidths()
  463. {
  464.     long alnlen= 0;
  465.     long i, nseq= fSeqList->GetSize();
  466.     for (i=0; i<nseq; i++) {
  467.         DSequence* aSeq= fSeqList->SeqAt(i);
  468.         if (fHaveAutoseq)  
  469.             alnlen= Max( alnlen, ((DAsmSequence*)aSeq)->NumPoints());
  470.         else
  471.             alnlen= Max(alnlen, aSeq->LengthF()); 
  472.         if (fMaskLevel>0 || aSeq->Masks()) aSeq->FixMasks();
  473.         }
  474.     alnlen += 30; 
  475.     if (alnlen > GetMaxCols()) ChangeColSize( -1, alnlen-GetMaxCols());
  476.     SetItemWidth( 0, GetMaxCols(), gAlnCharWidth);  
  477.     //if (fDoc && fDoc->fAlnHIndex) fDoc->fAlnHIndex->UpdateWidth(); //keep ruler in sync
  478. }
  479.  
  480.  
  481.  
  482. void DAsmView::SetViewMode(short viewmode) 
  483. {
  484.     short  t, i;
  485.     switch (viewmode) {
  486.     
  487.         case kShowTraces: 
  488.             for (t=0; t<4; t++) fShowTrace[t]= true;
  489.             this->fMaskLevel= 1;
  490.             fBaseCallPop->LimitTrace(-1);
  491.             goto caseMainSet;
  492.             
  493.         case kShowTraceA: 
  494.             i= 0; goto caseTraceI;
  495.         case kShowTraceC: 
  496.             i= 1; goto caseTraceI;
  497.         case kShowTraceG: 
  498.             i= 2; goto caseTraceI;
  499.         case kShowTraceT: 
  500.             i= 3; //goto caseTraceI;
  501.         caseTraceI:
  502.             for (t=0; t<4; t++) fShowTrace[t]= false;
  503.             fShowTrace[i]= true;
  504.             fBaseCallPop->LimitTrace(i);
  505.             this->fMaskLevel= 1;
  506.             // goto caseMainSet;
  507.         case kModeSlide: 
  508.         caseMainSet:
  509.             this->SetTextLock( true);
  510.             if (this->fMaskLevel>0) this->Invalidate();
  511.             this->fMaskLevel= 0; 
  512.             break;
  513.             
  514.         case kModeEdit:  
  515.             this->SetTextLock( false);
  516.             if (this->fMaskLevel>0) this->Invalidate();
  517.             this->fMaskLevel= 0; 
  518.             break;
  519.             
  520.         default :
  521.             break;
  522.         }
  523. }
  524.  
  525.  
  526.  
  527.  
  528.  
  529.  
  530.  
  531.  
  532.  
  533.  
  534. static void DrawTrace( long atx, long y0, short t, TraceBase* trace, 
  535.                     long startcol, long stopcol, short cwidth, float scale)
  536. {
  537. #define kTYScale 0.25     // need Scale of ht !
  538.     //short    cwidth= GetItemWidth(0); 
  539.     long aty;
  540.     Nlm_MoveTo(atx, y0);
  541.     for (long i= startcol+1; i<stopcol; i++) {
  542.         //if (fWidths) atx += GetItemWidth(i); else
  543.         atx += cwidth;
  544.         aty = y0 - (long)(trace[i].tr[t] * scale);
  545.         Nlm_LineTo( atx, aty);
  546.         }
  547. }
  548.  
  549.  
  550. #ifdef USEDRAWBASE
  551.  
  552. class DrawBasesA
  553. {
  554. public:
  555.     Nlm_PoinT pt;
  556.     long            endx, pend, indx, len, cw, cht;
  557.     long            row, ytop, ybot;
  558.     char            ch, lastch, *pText;
  559.     DAsmView * tview;
  560.     Boolean      swapBackcolor, fDoAll;
  561.     float         fScale;
  562.     char            fAtch;
  563.     Boolean     fIsGrey;
  564.     
  565.     DrawBasesA() : fIsGrey(false) {}
  566.     virtual void doDraw(DAsmView* theView, baseColors theColors, Boolean backcolor,
  567.                char*    theText, long theIndx, long theLen, long theRow);
  568.     virtual void Calc();
  569.     
  570.     virtual void DrawSub(baseColors colors);
  571.     virtual void DrawORFMasks(baseColors colors, short masklevel);
  572.     virtual void DrawTraces(baseColors colors);
  573. };
  574.  
  575. class DrawGreyBasesA : public DrawBasesA
  576. {
  577. public:    
  578.     DrawGreyBasesA() { fIsGrey = true; }
  579. };
  580.  
  581.  
  582.  
  583. void DrawBasesA::Calc() 
  584. {
  585.     long skip;
  586.     cht= tview->GetItemHeight(row);
  587.     cw = tview->GetItemWidth(0); 
  588.  
  589.     DAsmSequence* aSeq= (DAsmSequence*) tview->fCurSeq;
  590.     fScale= kTracextraHeight;
  591.     short t, att, nt;
  592.     for (t= 0, att= 0, nt= 0; t<4; t++) if (tview->fShowTrace[t]) { att= t; nt++; } 
  593.     if (nt==1) {
  594.         switch (att) {
  595.             case 0: fAtch= 'A'; break;
  596.             case 1: fAtch= 'C'; break;
  597.             case 2: fAtch= 'G'; break;
  598.             case 3: fAtch= 'T'; break;
  599.             }
  600.         fScale /= aSeq->MaxHeight(att);
  601.         fDoAll= false;
  602.         }
  603.     else {
  604.         fDoAll= true;
  605.         fScale /= aSeq->MaxHeight(4);
  606.         }
  607.         
  608.     Nlm_GetPen( &pt);
  609.     ytop= pt.y-cht+2;
  610.     ybot= pt.y+2;  
  611.     if (pt.x < 0) {
  612.         skip= (-pt.x) / cw;
  613.       indx+= skip;
  614.         len -= skip;
  615.         Nlm_MoveTo( pt.x + skip*cw, pt.y);
  616.         }
  617.     pend= len * cw;
  618.     
  619.     if (pend > tview->GetRect().right) {   
  620.         skip= (pend - tview->GetRect().right) / cw;  
  621.         len -= skip;
  622.         }
  623.     endx= indx + len - 1;
  624. }
  625.  
  626.  
  627.  
  628.  
  629. void DrawBasesA::doDraw(DAsmView* theView, baseColors theColors, Boolean backcolor,
  630.            char*    theText, long theIndx, long theLen, long theRow)
  631. {
  632.     tview= theView;
  633.     //colors= &theColors;
  634.     pText= theText;
  635.     indx= theIndx;
  636.     len= theLen;
  637.     row= theRow;
  638.     lastch= 0;
  639.     swapBackcolor= backcolor;
  640.  
  641.     Calc();
  642.  
  643.     if (swapBackcolor) Nlm_CopyMode();
  644.     Nlm_PoinT savept= pt;
  645.     
  646. #if 1
  647.     if (tview->fCurSeq->ShowTrace()) {
  648.         pt= savept;
  649.         pt.y -= 2;  
  650.         DrawTraces(theColors);        
  651.         savept.y -= kTracextraHeight;
  652.         pt= savept;
  653.         Nlm_MoveTo( pt.x, pt.y);
  654.         }
  655. #endif        
  656.  
  657. #if 1
  658.     if (tview->fCurSeq->ShowORF()) {
  659.         pt= savept;
  660.         pt.y -= (kORFxtraHeight - 3);
  661.         DrawORFMasks(theColors, 5);            
  662.         //pt= savept; pt.y -= 7;
  663.         //DrawORFMasks(theColors, 6);            
  664.         //pt= savept; /pt.y - 2;
  665.         //DrawORFMasks(theColors, 7);            
  666.         
  667.         savept.y -= kORFxtraHeight;
  668.         pt= savept;
  669.         Nlm_MoveTo( pt.x, pt.y);
  670.         }
  671. #endif
  672.  
  673.     DrawSub(theColors);
  674.     
  675. #if 0
  676.     if (tview->fCurSeq->ShowRE()) {
  677.         DrawREMasks();            
  678.         }
  679. #endif
  680.  
  681.     if (swapBackcolor) Nlm_MergeMode();
  682. }
  683.  
  684.  
  685.  
  686. void DrawBasesA::DrawSub(baseColors colors)
  687. {
  688.     Nlm_RecT    crec;  
  689.     DAsmSequence* aSeq= (DAsmSequence*) tview->fCurSeq;
  690.     TraceBase* trace= aSeq->Trace();
  691.     
  692.     for (long i= indx; i<=endx; i++) {
  693.  
  694.         Boolean notInverted= true;
  695.         ch= trace[i].base;
  696.  
  697.         if ( (fDoAll && ch > ' ') || ch == fAtch) {
  698.             //if (fIsGrey) {
  699.                 //if (swapBackcolor) Nlm_SetBackColor( tview->fColcolors[i-indx]);  else 
  700.                 //Nlm_SetColor( tview->fColcolors[i-indx]);
  701.                 //}
  702.             //else 
  703.             if (ch!=lastch) {
  704.                 //if (swapBackcolor) Nlm_SetBackColor( colors[ch-' ']);  else 
  705.                 Nlm_SetColor( colors[ch-' ']);
  706.                 }
  707.                 
  708.             Nlm_PaintChar(ch);
  709.             lastch= ch;
  710.             }
  711.                 
  712.         if (notInverted) {
  713.           if (tview->fSelection->IsSelected(row, i)) {
  714.                 Nlm_LoadRect( &crec, pt.x, ytop, pt.x+cw, ybot); //??
  715.                 tview->DTableView::InvertRect( crec);
  716.                 }
  717.             }
  718.             
  719.         pt.x += cw;
  720.         }
  721.     Nlm_Black();
  722. }
  723.  
  724.  
  725.  
  726. void DrawBasesA::DrawTraces(baseColors colors)
  727. {
  728.     DAsmSequence* aSeq= (DAsmSequence*) tview->fCurSeq;
  729.     for (short t= 0; t<4; t++) if (tview->fShowTrace[t]) {
  730.         char ch;
  731.         switch (t) {
  732.             case 0: ch= 'A'; break;
  733.             case 1: ch= 'C'; break;
  734.             case 2: ch= 'G'; break;
  735.             case 3: ch= 'T'; break;
  736.             }
  737.         Nlm_SetColor( colors[ch-' ']);
  738.         ::DrawTrace( pt.x, pt.y, t, aSeq->Trace(), indx, endx, cw, fScale);
  739.         }
  740.     Nlm_Black();
  741. }
  742.  
  743.  
  744. // this should move into DSeqView's DrawBases class !! not useful w/ trace view 
  745. void DrawBasesA::DrawORFMasks(baseColors colors, short masklevel)
  746. {
  747.     enum { otic = 3 };
  748.     long        lastx, startx = pt.x;
  749.     Boolean inorf= false;
  750.     
  751.     for (long i= indx; i<=endx; i++) {
  752.         ch= pText[i];
  753.         if (ch >= ' ') {
  754.             short maskval= tview->fCurSeq->MaskAt(i, masklevel);
  755.             if (maskval && !inorf) { 
  756.                 startx= lastx= pt.x; 
  757.                 inorf= true; 
  758.                 }
  759.             else if ( !maskval 
  760.                 && inorf 
  761.                 && (DSequence::NucleicBits(ch) != DSequence::kMaskIndel)
  762.                 ) {
  763.                 Nlm_MoveTo( startx, pt.y-otic);
  764.                 Nlm_LineTo( startx, pt.y);
  765.                 Nlm_LineTo( lastx, pt.y);
  766.                 Nlm_LineTo( lastx, pt.y-otic);
  767.                 inorf= false;
  768.                 }
  769.             lastx= pt.x;
  770.             pt.x += cw;
  771.             }
  772.         }
  773.     if (inorf) {
  774.         Nlm_MoveTo( startx, pt.y-otic);
  775.         Nlm_LineTo( startx, pt.y);
  776.         Nlm_LineTo( pt.x, pt.y);
  777.         inorf= false;
  778.         }
  779.         
  780.     //Nlm_Black();
  781. }
  782.  
  783.     
  784. DrawBasesA         gDrawBasesA;
  785. DrawGreyBasesA     gDrawGreyBasesA;
  786. #endif  // USEDRAWBASE
  787.  
  788.  
  789. Local Boolean          gDoDrawColors = false;
  790.  
  791. void DAsmView::DrawAllColors(Nlm_RecT r, long row)
  792.     DAsmSequence* aSeq= (DAsmSequence*)fSeqList->SeqAt(row);
  793.     if (!aSeq || !aSeq->Bases()) return;
  794.     
  795.     Boolean dotrace= aSeq->ShowTrace() && (aSeq->Kind() == DAsmSequence::kAutoseq);
  796.     if (!dotrace) { DAlnView::DrawAllColors( r, row); return; }
  797.  
  798. #ifndef USEDRAWBASE
  799.     gDoDrawColors= true;
  800.     DrawNoColors( r, row);
  801.     gDoDrawColors= false;
  802.     
  803. #else
  804.     long  len, newright, stopcol, startcol = GetLeft(); 
  805.     char* hSeq= aSeq->Bases();
  806.     fCurSeq= aSeq;
  807.  
  808.     for (stopcol= startcol, newright= r.left; 
  809.         stopcol<GetMaxCols() && newright<r.right;
  810.         stopcol++) {
  811.         if (fWidths) newright += GetItemWidth(stopcol); else 
  812.         newright += GetItemWidth(0);
  813.         }
  814.             
  815.     len= Min( stopcol, ((DAsmSequence*)aSeq)->NumPoints());
  816.     //len= Min( aSeq->LengthF(), stopcol);
  817.     len -= startcol;
  818.     if (len>0) {
  819.         Nlm_MoveTo( r.left, r.bottom-2); //bottom-5
  820. #if 0
  821.         if (aSeq->Kind() == DSequence::kAmino)
  822.             gDrawBasesA.doDraw(this, DBaseColors::gAAcolors, gSwapBackground,
  823.                      hSeq, startcol, len, row);
  824.         else
  825. #endif
  826.             gDrawBasesA.doDraw(this, DBaseColors::gNAcolors, gSwapBackground,
  827.                      hSeq, startcol, len, row);
  828.         }
  829.  
  830.     fColsDrawn= stopcol - startcol;
  831. #endif
  832. }  
  833.  
  834.  
  835.  
  836. void DAsmView::DrawNoColors(Nlm_RecT r, long row)
  837.     DAsmSequence* aSeq= (DAsmSequence*)fSeqList->SeqAt(row);
  838.     if (!aSeq || !aSeq->Bases()) return;
  839.     
  840.     Boolean dotrace= aSeq->ShowTrace() && (aSeq->Kind() == DAsmSequence::kAutoseq);
  841.     if (!dotrace) { DAlnView::DrawNoColors( r, row); return; }
  842.     
  843.     long  y0, len, atx, aty, stopcol, startcol = GetLeft(), newright;
  844.     short cwidth= GetItemWidth(0); 
  845.     TraceBase* trace = aSeq->Trace();
  846.     if (!trace) return; // early calls here before traces read !
  847.     
  848.     for (stopcol= startcol, newright= r.left; 
  849.         stopcol<GetMaxCols() && newright<r.right; 
  850.         stopcol++) {
  851.             //if (fWidths) newright += GetItemWidth(stopcol); else 
  852.             newright += cwidth;
  853.             }
  854.     
  855.     //len= Min( aSeq->LengthF(), stopcol);
  856.     len = Min( stopcol, ((DAsmSequence*)aSeq)->NumPoints());  
  857.     len -= startcol;
  858.     if (len>0) {
  859.         atx= r.left;
  860.         aty= y0 = r.bottom-2;
  861.         stopcol= startcol + len;
  862.  
  863.         float scale = kTracextraHeight;
  864.         short t, att, nt;
  865.         char ch, atch, lastch= 0;
  866.         short xoffset= gRealCharWidth / 2;
  867.         
  868.         for (t= 0, att= 0, nt= 0; t<4; t++) if (this->fShowTrace[t]) { att= t; nt++; } 
  869.         if (nt==1) {
  870.             switch (att) {
  871.                 case 0: atch= 'A'; break;
  872.                 case 1: atch= 'C'; break;
  873.                 case 2: atch= 'G'; break;
  874.                 case 3: atch= 'T'; break;
  875.                 }
  876.             scale /= aSeq->MaxHeight(att);
  877.             }
  878.         else scale /= aSeq->MaxHeight(4);
  879.         
  880.                 // draw traces
  881.         if (aSeq->ShowTrace()) {
  882.           for ( t= 0; t<4; t++)
  883.           if (fShowTrace[t]) {
  884.                 switch (t) {
  885.                     case 0: ch= 'A'; break;
  886.                     case 1: ch= 'C'; break;
  887.                     case 2: ch= 'G'; break;
  888.                     case 3: ch= 'T'; break;
  889.                     }
  890.                 if (gDoDrawColors) Nlm_SetColor( DBaseColors::gNAcolors[ch-' ']);
  891.                 ::DrawTrace( atx, aty, t, aSeq->Trace(), startcol, stopcol, cwidth, scale);
  892.                 }
  893.             Nlm_Black();
  894.             aty -= ( kTracextraHeight - 2); //??
  895.             }
  896.         
  897.             // draw ORFs
  898.         if (aSeq->ShowORF()) {
  899.             aty -= ( kORFxtraHeight ); //??
  900.             }
  901.         
  902.             // draw bases
  903.         aty= r.top + gAlnCharHeight - 2; //??
  904.         for (long i= startcol; i<stopcol; i++) {
  905.             long y1, x1;
  906.             ch= trace[i].base;
  907.             if ( (nt  > 1 && ch > ' ')
  908.               || (nt == 1 && ch == atch)) {
  909.  
  910.                 if (lastch != ch && gDoDrawColors) 
  911.                     Nlm_SetColor( DBaseColors::gNAcolors[ch-' ']);
  912.  
  913.                 switch (ch) {
  914.                     case 'A': t= 0; break;
  915.                     case 'C': t= 1; break;
  916.                     case 'G': t= 2; break;
  917.                     case 'T': t= 3; break;
  918.                     }
  919.                     
  920.                 if (fBaseOnTrace) { 
  921.                     y1 = Max( aty, y0 - (long)(trace[i].tr[t] * scale) - 2);
  922.                     }
  923.                 else 
  924.                     y1= aty;
  925.                 
  926.                 Nlm_MoveTo(atx - xoffset, y1);
  927.                 Nlm_PaintChar(ch);
  928.                 lastch= ch;
  929.                 }
  930.           if (this->fSelection->IsSelected(row, i)) {
  931.                 Nlm_RecT crec;
  932.                 Nlm_LoadRect( &crec, atx, r.top, atx+cwidth, r.bottom); 
  933.                 DTableView::InvertRect( crec); 
  934.                 }
  935.             //if (fWidths) atx += GetItemWidth(i); else
  936.             atx += cwidth;
  937.             }
  938.       }
  939.     Nlm_Black();
  940.     fColsDrawn= stopcol - startcol;
  941. }  
  942.  
  943.         
  944. void DAsmView::Draw()
  945. {
  946.     DAlnView::Draw();
  947. }
  948.  
  949.  
  950. void DAsmView::DrawRow(Nlm_RecT r, long row)
  951. {
  952.     DAlnView::DrawRow(r, row);
  953. }
  954.  
  955.         
  956.  
  957.  
  958.  
  959.  
  960.